<template>
  <div class="PersonnerAllocationComponent">
    <!-- tab切换 省级和市级 开始 -->
    <div class="tabBarBox">
      <!-- <div
        :class="[clickTab == 1 ? 'tabBarBox_pie_ture' : 'tabBarBox_pie_false']"
        @click="FnClickTab(1)"
      >
        {{ countyName }}
      </div>
      <div
        :class="[clickTab == 2 ? 'tabBarBox_pie_ture' : 'tabBarBox_pie_false']"
        @click="FnClickTab(2)"
        v-show="countyType == 0"
      >
        省级
      </div> -->
      <div
        :class="[clickTab == 1 ? 'tabBarBox_pie_ture' : 'tabBarBox_pie_false']"
        @click="FnClickTab(1)"
      >
        市级
      </div>
      <div
        :class="[clickTab == 2 ? 'tabBarBox_pie_ture' : 'tabBarBox_pie_false']"
        @click="FnClickTab(2)"
      >
        省级
      </div>
    </div>
    <!-- tab切换 省级和市级 结束 -->
    <!-- 列表 开始 -->
    <!-- table1 开始 -->
    <div v-show="clickTab == 1 && loading == 1">
      <div class="listInfo">
        <ul>
          <li class="headBox">
            <div
              v-for="(item, indexHead) in heardData"
              :key="indexHead"
              :class="item.className"
              style="margin:0px 10px 0 10px"
            >
              {{ item.title }}
            </div>
          </li>

          <el-scrollbar class="cmp-scrollbar-y " style="height:230px;">
            <li
              v-for="(item,
              indexContent) in personnerAllocationComponentInfoOne"
              :key="indexContent"
              class="contentBox"
              style="margin:0px 10px 0 10px"
              :class="{ off: indexContent % 2 == 0 }"
            >
              <div class="contentBox_pie">{{ indexContent + 1 }}</div>
              <div class="contentBox_pie" style="width:auto;color:#e8643d">
                {{ item.area }}
              </div>
              <div class="contentBox_pie">{{ item.percent }}</div>
            </li>
          </el-scrollbar>
        </ul>
      </div>
    </div>
    <!-- table1 结束 -->
    <!-- table2 开始 -->
    <div>
      <div v-show="clickTab == 2 && loading == 1">
        <div class="listInfo">
          <ul>
            <li class="headBox">
              <div
                v-for="(item, indexHead) in heardData"
                :key="indexHead"
                :class="item.className"
                style="margin:0px 10px 0 10px"
              >
                {{ item.title }}
              </div>
            </li>
            <el-scrollbar class="cmp-scrollbar-y " style="height:240px;">
              <li
                v-for="(item,
                indexContent) in personnerAllocationComponentInfoTwo"
                :key="indexContent"
                class="contentBox"
                style="margin:0px 10px 0 10px"
                :class="{ off: indexContent % 2 == 0 }"
              >
                <div class="contentBox_pie">{{ indexContent + 1 }}</div>
                <div class="contentBox_pie" style="width:auto;color:#e8643d">
                  {{ item.area }}
                </div>
                <div class="contentBox_pie" style="padding-right:10px;">
                  {{ item.percent }}
                </div>
              </li>
            </el-scrollbar>
          </ul>
        </div>
      </div>
    </div>
    <!-- table2 结束 -->
    <!-- 列表 结束 -->
    <!-- loading 开始 -->
    <div class="loading" v-show="loading === 2">
      <el-row v-loading="loadingTrue">
        <el-col :span="24"></el-col>
      </el-row>
    </div>
    <!-- loading 结束 -->
    <!-- 暂无数据 开始-->
    <div class="noData" v-show="noData === 2">
      暂无数据
    </div>
    <!-- 暂无数据 结束 -->
  </div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Watch } from "vue-property-decorator";
import { ZhtsServer } from "@/api/installServer";
@Component({
  name: "PersonnerAllocationComponent",
  components: {}
})
export default class PersonnerAllocationComponent extends Vue {
  @Prop() private timeData: any; // 定义查询时间
  @Prop({ default: "move_in" }) private migrateType: any; // 定义查询类型  迁入 还是 迁出
  private areaId: any = "420100"; // 定义变量 接受仓库里的行政区划状态
  private personnerAllocationComponentInfoOne: any = ""; // 定义变量 用于接收请求过来的数据
  private personnerAllocationComponentInfoTwo: any = ""; // 定义变量 用于接收请求过来的数据
  private countyType: any = 0; // 0为全国 1为显示市，2为显示区
  private countyName: any = "市级";
  private clickTab: any = 1; // 切换tab栏
  private heardData: any = [
      {
          title: "序号",
          className: "headBox_num"
      },
      {
          title: "名称",
          className: "headBox_pie"
      },
      {
          title: "比例",
          className: "headBox_pie"
      },
  ];
  private loading: any = 1; // 定义loading 1. 是loading不显示 2. 是loading显示
  private noData: any = 1; // 暂无数据 1 是不显示 2 是显示
  private loadingTrue: any = true;
  //   点击切换 省级和市级
  private FnClickTab(val: any): void {
    this.clickTab = val;
    this.$store.dispatch("ZhtsModule/setDate", this.timeData);
    this.$store.dispatch(
      "ZhtsModule/setMigrateType",
      this.migrateType + this.clickTab
    );
    console.log('当前store' , this.$store.state.ZhtsModule.date , this.$store.state.ZhtsModule.migrateType)
  }
  @Watch("$store.state.ZhtsModule.district.id")
  private FnCountyType(): void {
    const CountyType = this.$store.state.ZhtsModule.district.id;
    const searchCity = "0000";
    if (CountyType === "100000") {
      this.countyType = 0;
      this.countyName = "市级";
    } else if (CountyType.indexOf(searchCity) !== -1) {
      const result = CountyType.match(searchCity)[0];
      this.countyType = 1;
      this.countyName = "市级";
      console.log("查找结果0000：", result);
    } else {
      this.countyType = 2;
      this.countyName = "区/县";
    }
  }
  // 获取人员迁徙详情数据
  @Watch("timeData")
  @Watch("migrateType")
  @Watch("$store.state.ZhtsModule.district")
  private getPersonAllocationComponent(): void {
    this.$store.dispatch("ZhtsModule/setDate", this.timeData);
    this.$store.dispatch(
      "ZhtsModule/setMigrateType",
      this.migrateType + this.clickTab
    );
    console.log('当前store' , this.$store.state.ZhtsModule.date , this.$store.state.ZhtsModule.migrateType)
    this.noData = 1;
    this.loading = 2;
    ZhtsServer.getPersonAllocationComponent({
      date: this.timeData,
      migrate_type: this.migrateType + "1",
      area_id: this.$store.state.ZhtsModule.district.id
    }).then((res: any) => {
      this.loading = 1;
      if (res.data.length === 0) {
        this.noData = 2;
      }
      this.personnerAllocationComponentInfoOne = res.data;
      console.log("市级数据:", this.personnerAllocationComponentInfoOne);
    });
    ZhtsServer.getPersonAllocationComponent({
      date: this.timeData,
      migrate_type: this.migrateType + "2",
      area_id: this.$store.state.ZhtsModule.district.id
    }).then((res: any) => {
      if (res.data.length === 0) {
        this.noData = 2;
      }
      this.personnerAllocationComponentInfoTwo = res.data;
      console.log("省级数据:", this.personnerAllocationComponentInfoTwo);
    });
  }
  private mounted() {
    this.loading = 2;
    ZhtsServer.getPersonAllocationComponent({
      date: this.timeData,
      migrate_type: this.migrateType + "1",
      area_id: this.$store.state.ZhtsModule.district.id
    }).then((res: any) => {
      this.loading = 1;
      if (res.data.length === 0) {
        this.noData = 2;
      }
      this.personnerAllocationComponentInfoOne = res.data;
      console.log("市级数据:", this.personnerAllocationComponentInfoOne);
    });
    ZhtsServer.getPersonAllocationComponent({
      date: this.timeData,
      migrate_type: this.migrateType + "2",
      area_id: this.$store.state.ZhtsModule.district.id
    }).then((res: any) => {
      if (res.data.length === 0) {
        this.noData = 2;
      }
      this.personnerAllocationComponentInfoTwo = res.data;
      console.log("省级数据:", this.personnerAllocationComponentInfoTwo);
    });
  }
}
</script>
<style lang="less" scoped>
ul,
li {
  list-style: none;
  padding: 0;
}
.tabBarBox {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
}
.tabBarBox_pie_ture {
  width: 193px;
  height: 50px;
  background: url("../../../assets/img/zhts/iconMaterial.png") no-repeat;
  background-position: -21px -130px;
  text-align: center;
  line-height: 50px;
  color: #ffe92c;
  cursor: pointer;
  font-size: 18px;
}
.tabBarBox_pie_false {
  width: 193px;
  height: 50px;
  background: url("../../../assets/img/zhts/iconMaterial.png") no-repeat;
  background-position: -259px -130px;
  text-align: center;
  line-height: 50px;
  color: #c2e7f2;
  cursor: pointer;
  font-size: 18px;
}
.listInfo {
  width: 100%;
  // height: 267px;
  padding: 0 10px;
  box-sizing: border-box;
  overflow: auto;
  height: 100%;
}
.listInfo::-webkit-scrollbar {
  display: none;
}
.headBox {
  display: flex;
  justify-content: space-between;
}
.headBox_num{
  width: 80px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-weight: 800;
  color: #fff;
}
.headBox_pie {
  width: 80px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-weight: 800;
  color: #fff;
}
.contentBox {
  display: flex;
  justify-content: space-between;
  &:nth-child(1) {
    .contentBox_pie:nth-child(1) {
      background-image: url("../../../assets/img/zhts/one.png");
    }
  }
  &:nth-child(2) {
    .contentBox_pie:nth-child(1) {
      background-image: url("../../../assets/img/zhts/two.png");
    }
  }
  &:nth-child(3) {
    .contentBox_pie:nth-child(1) {
      background-image: url("../../../assets/img/zhts/three.png");
    }
  }
}
.contentBox_pie {
  width: 80px;
  height: 39px;
  text-align: center;
  line-height: 39px;
  font-weight: 800;
  color: #c2e7f2;
  &:nth-child(1) {
    background: url("../../../assets/img/zhts/four.png") no-repeat 26px
      center;
  }
  &:nth-child(2) {
    text-align: center;
    flex: 2;
  }
}
.off {
  background-color: rgba(36, 147, 221, 0.15);
}
.loading {
  width: 100%;
  height: 80px;
  font-size: 14px;
  text-align: center;
  font-weight: 400;
  position: absolute;
  top: 724px;
  z-index: 999;
  color: #fff;
}
.noData {
  width: 100%;
  height: 80px;
  font-size: 14px;
  text-align: center;
  font-weight: 400;
  position: absolute;
  top: 724px;
  z-index: 999;
  color: #fff;
}
</style>
